<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2020/04/23
 * Time: 13:45
 */

namespace HiCommon\Model;

class GoodsSaleTagRelation extends Base
{

    protected $table = 'goods_sale_tag_relation';

    protected $guarded = [];

    //public $timestamps = false;

    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [];

    //一对一关联服务标签
    public function sale_tag()
    {
        return $this->hasOne(GoodsSaleTag::class, 'id', 'sale_tag_id')
            ->select(['id', 'name', 'notes']);
    }

    /**
     * 获取图片可用链接
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getImgUrlAttribute($value)
    {
        $arr_data = [
            'src' => $value,
            'full_src' => oss_full_url($value),
        ];
        return $arr_data;
    }

    /**
     * 扩展信息
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getExtendAttribute()
    {
        $s_created_at = $this->created_at;
        $arr_data = $this->arr_state_display_name();
        $arr_data['created_at'] = ymd_friendly_date($s_created_at);
        $arr_data['api'] = $this->table_field_api();

        return $arr_data;
    }


    /**
     * 获取state值和注释的集合
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function arr_state_name()
    {
        return $this->hi_arr_state_name($this->state_arr());
    }

    /**
     * 获取state值和注释的集合
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function arr_state_display_name()
    {
        return $this->hi_arr_state_display_name($this->state_arr());
    }


}